<template>
	<view class="ikz-bid">
		<ikz-loading :css-data="loading_css"></ikz-loading>
		<view class="ikz-top-bg">
			<image class="ikz-top-bg-img" :src="service_img"></image>
		</view>
		<view class="title_txt">
			跑跑乐
		</view>
		<view class="ikz-banner-box">
			<ikz-banner :show-data="banner_data" :css-data="banner_css"></ikz-banner>
		</view>
		<!-- Grid宫格布局 -->
		<view class="gridbox">
			<view class="itembox" v-for="(item,index) in gridlist" :key="index" @click="togird(item)">
				<image :src="item.Image" style="width: 104rpx;height: 104rpx;" mode=""></image>
				<view class="txt">
					{{item.txt}}
				</view>
			</view>
		</view>

		<!-- 失物招领和万能墙 -->
		<view class="wnbox">
			<view class="shiwbox" @click="toxunwu"> 
				<image src="/static/index/index_sw.png" style="width: 100%;height: 100%;" mode=""></image>
				<view class="kdtxt">
					<view class="siwu">
						失物招领
					</view>
					<view class="xiaotxt">
						建议一段话这多字
					</view>
				</view>
			</view>
			<view class="wanneng" @click="tolove">
				<image src="/static/index/index_wnq.png" style="width: 100%;height: 100%;" mode=""></image>
				<view class="kdtxt">
					<view class="siwu">
						表白墙
					</view>
					<view class="xiaotxt">
						这么多多多字
					</view>
				</view>
			</view>
		</view>
		<view class="default-height" style="width: 100%;height: 92rpx;"></view>
		<ikz-tabbar :show-data="tabbar_Data"></ikz-tabbar>
	</view>
</template>

<script>
	// 将分包的组件复制到公共
	import storeList from '@/pages/Component/Public/store/list.vue'
	import mainList from '@/pages/Component/Public/main-list/mainList.vue'
	import ikzBanner from '@/pages/Component/Public/Banner/public/banner/banner.vue';
	import ikzLoading from '@/pages/Component/Public/Loading/loading.vue';
	import ikzNotice from '@/pages/Component/Public/Notice/public/notice/notice.vue';
	import ikzMenu from '@/pages/Component/Public/Menu/public/menu2/menu.vue';
	import ikzAd from '@/pages/Component/Public/Ad/public/ad/ad.vue';
	import ikzGlist from '@/pages/Component/Public/Glist/public/glist/glist.vue';
	import ikzScreen from '@/pages/Component/Public/Screen/public/screen/screen.vue';
	import ikzTabbar from '@/pages/Component/Public/tab-bar/tab-bar.vue';
	var app = getApp( );
	import ikz from '@/pages/Common/tools.js';
	import Vue from 'vue'
	export default {
		components: {
			ikzBanner,
			ikzLoading,
			ikzNotice,
			ikzMenu,
			ikzAd,
			ikzGlist,
			ikzScreen,
			ikzTabbar,
			storeList,
			mainList
		},
		data( ) {
			return {
				// 超市外卖是否展示  
				wmshow: 0,
				// 校园贴吧是否展示
				tbshow: 0,
				listType: 1,
				selectedTab: 1,
				tabbar_Data: {
					type: 0,
					list: [ ]
				},
				show_info: {
					list: [ ]
				},
				ad_css: {},
				banner_data: {
					ban_page: 2
				},
				banner_css: {
					margin_top: 0
				},
				loading_css: {
					display: 'flex'
				},
				service_img: '/static/index/bg.png',
				menu_css: {
					background_color: '#fff',
					bg_border_radius: 15,
					border_radius: '50%',
					color: '#888888',
					margin_top: 15,
					num: '4',
					width: 95
				},
				default_agent: {},
				page: 1,
				limit: 10,
				load_more: 2,
				apply_receive_image_show: 1,
				gridlist: [ {
						id: 0,
						Image: '/static/index/index_pt.png',
						txt: '校园跑腿',
						url: '/pages/Component/Module/Campus/Program/Runerrands/index/index?type=1'
					},
					{
						id: 1,
						Image: '/static/index/index_st.png',
						txt: '食堂代买',
						url: '/pages/Component/Module/Campus/Program/Runerrands/index/index?type=3'
					},
					{
						id: 2,
						Image: '/static/index/index_cs.png',
						txt: '超市代买',
						url: '/pages/Component/Module/Campus/Program/Runerrands/index/index?type=4'
					},
					{
						id: 3,
						Image: '/static/index/index_kd.png',
						txt: '快递代取',
						url: '/pages/Component/Module/Campus/Program/Runerrands/index/index?type=2'
					},
					{
						id: 4,
						Image: '/static/index/index_kddj.png',
						txt: '快递代寄',
						url: '/pages/Component/Module/Campus/Program/Runerrands/index/index?type=5'
					},
					{
						id: 5,
						Image: '/static/index/index_wn.png',
						txt: '万能帮',
						url: '/pages/Component/Module/Campus/Program/Runerrands/index/index?type=6'
					}
				]
			};
		},
		onLoad( ) {
			this.tabbar_Data.list = app.globalData.tabBarInfo
			uni.hideTabBar( )
			const obj = wx.getEnterOptionsSync( );
			if ( obj.scene == 1047 || obj.scene == 1048 || obj.scene == 1049 ) {
				var pathId = {
					id: obj.query.scene
				}
				if ( pathId.id ) {
					uni.setStorageSync( 'default_agent', pathId );
				}
			}
			uni.setNavigationBarTitle( {
				title: app.globalData.miniapp_title
			} );
			this.page = 1;
			this.show_info = {
				list: [ ]
			}
			this.load_more = 2;
			this.homeInfo( res => {
				this.loading_css.display = 'none';
			} );
			this.$forceUpdate( );
			// uni.showShareMenu({ 
			//   withShareTicket: true,
			//   menus: ['shareAppMessage', 'shareTimeline']
			// }) 
		},
		onShareTimeline( ) {
			return {
				title: '自定义转发标题',
				query: '/page/Home/index?id=123'
			}
		},
		onShareAppMessage( ) {
			// const promise = new Promise(resolve => {
			//   setTimeout(() => {
			//     resolve({ 
			//       title: '自定义转发标题',
			//       imageUrl:'https://xybaddon.maiwd.cn/shareButton.png',
			//     })  
			//   }, 2000) 
			// })  
			return {
				title: app.globalData.share_info.share_title,
				path: '/pages/Home/index',
				imageUrl: app.globalData.share_info.share_img,
			}
		},
		onShow( ) {
			if ( app.globalData.default_agent.title == undefined ) {
				this.default_agent = {
					title: "请选择学校"
				};
			} else {
				this.default_agent = app.globalData.default_agent;
			}
			if ( uni.getStorageSync( 'local_user_session' ) ) {
				this.getBaseinfo( )
			}
			if ( this.listType == 2 ) {
				this.$refs.storeList.getStoreList( )
			} 
			this.bannerlist()
		},
		onPullDownRefresh( ) {
			this.homeInfo( res => {
				uni.stopPullDownRefresh( );
			} );
			this.page = 1;
		},
		onReachBottom( ) {
			if ( this.load_more == 2 ) {
				this.page++;
				this.load_more = 3;
			}
			if ( this.listType == 2 ) {
				this.$refs.storeList.onBottom( )
			}
		},
		methods: {
			bannerlist(){
				var path = '/index/carousel';
				var data = {};
				ikz.get( path, data, res => {
					console.log(res,'轮播图');
					if ( res.data.code == 1) {
						this.banner_data = res.data.data
					} else {
						uni.showModal( {
							title: '提示',
							content: '服务器繁忙，请稍后再试',
							showCancel: false,
							success: function( res ) {}
						} );
					}
				} );
			},
			tolove( ) {
				uni.navigateTo( {
					url: '/pages/Home/loveq/loveq'
				} )
			},
			toxunwu(){
				uni.navigateTo( {
					url: '/pages/Home/xunwu/xunwu'
				} )
			},
			togird( item ) {
				uni.navigateTo( {
					url: item.url
				} )
			},
			switchTab( tab ) {
				console.log( tab, 'tab' );
				this.listType = tab;
				this.selectedTab = tab;
				this.$nextTick( ( ) => {
					if ( tab == 2 ) {
						this.$refs.storeList.getStoreList( );
					} 
				} );
			},
			//获取用户信息
			getBaseinfo( ) {
				var path = '/xyb/user/baseinfo';
				var data = {
					token: uni.getStorageSync( 'local_user_session' ),
					app_plat: "MP-WEIXIN"
				};
				ikz.get( path, data, res => {
					if ( res.data.code ) {
						console.log( "值是", res.data.data );
						var user_address = res.data.data.user_address_list
						if ( user_address.length ) {
							getApp( ).globalData.user_address.address_all = ''; //地址数据

							getApp( ).globalData.user_address.address_all = user_address; //地址数据
							for ( var i = 0; i < user_address.length; i++ ) {
								if ( user_address[ i ].defaults ) {
									getApp( ).globalData.user_address.address_default = user_address[ i ]; //默认地址
									getApp( ).globalData.user_address.address_current = user_address[ i ]; //当前
								}
							}
							if ( getApp( ).globalData.user_address.address_default == '' ) {
								getApp( ).globalData.user_address.address_default = user_address[ 0 ]; //默认地址
								getApp( ).globalData.user_address.address_current = user_address[ 0 ]; //当前
							}
						} else {
							getApp( ).globalData.user_address.address_all = ''; //地址数据
							getApp( ).globalData.user_address.address_default = ''; //默认地址
							getApp( ).globalData.user_address.address_current = ''; //当前
						}

						//设置用户信息
						if ( res.data.data.user_info.nickname ) {
							getApp( ).globalData.user_openinfo = res.data.data.user_info || {};
						} else {
							getApp( ).globalData.user_openinfo = {};
						}



					}

				} );
			},
			//获取首页信息 
			homeInfo( fn ) {
				var path = '/xyb/mp_weixin_home/index';
				var url = app.globalData.adminPath + path;
				var _that = this;
				uni.request( {
					url: url,
					header: {
						"Content-Type": "application/x-www-form-urlencoded"
					},
					data: {
						"agent_id": uni.getStorageSync( 'default_agent' ).id || ''
					},
					method: 'POST',
					success: function( res ) {
						if ( res.data.code == 1 ) {
							_that.apply_receive_image_show = res.data.data.apply_receive_image_show;
							// _that.banner_data = res.data.data.carousel_list;
							_that.$forceUpdate( );
						} else {
							uni.showModal( {
								title: '提示',
								content: res.data.msg,
								showCancel: false,
								success: function( res ) {}
							} );
						}
						fn( );
					},
					fail: function( res ) {
						//调用接口失败或回传失败
						uni.showModal( {
							title: '服务器繁忙',
							content: '服务器繁忙或网络不稳定，请稍后再试！'
						} )
					},
				} )
			},
			//切换位置
			getPosition( ) {
				var path = '/pages/Component/Module/Campus/Program/school/index/index';
				ikz.nav( path, 'n', '' );
			},
			//不同意
			cancelTreaty( ) {
				//退出程序
				// plus.runtime.quit();
			},
			//查看平台协议
			getTreaty( e ) {
				var id = e.currentTarget.dataset.id;
				var path = '/pages/Component/Module/Login/treaty/index?id=' + id;
				ikz.nav( path, 'n', '' );
			},

			//请求页面数据
			getList( ) {

				var path = '/Supply/Wechat/Public/indexPage';
				var data = {
					longitude: this.longitude,
					latitude: this.latitude
				};
				ikz.get( path, data, res => {
					if ( res.data.status == 'success' ) {

					} else {
						uni.showModal( {
							title: '提示',
							content: '服务器繁忙，请稍后再试',
							showCancel: false,
							success: function( res ) {}
						} );
					}
					// if(that.pull_status){
					// 	this.$emit("change",'pull');
					// }
				} );
			},

			//跳转至招聘中心
			getRecriut( ) {
				let url = '/pages/Component/Module/Demand/Program/Recruit/index';
				ikz.nav( url, 'n' );
			},

		}
	};
</script>

<style scoped lang="scss">
	.ikz-tab {
		padding: 0 20rpx;
		display: flex;
		align-items: center;
		font-size: 32rpx;
		justify-content: space-between;

		.ikz-tab-item {
			padding-right: 16rpx;
			color: #333;

			&.active {
				color: #FED476;
				font-weight: 600;
			}
		}
	}

	.ikz-top-bg {
		position: fixed;
		top: 0px;
		left: 0px;
		z-index: -1;
	}

	.ikz-top-bg-img {
		width: 750rpx;
		height: 430rpx;
	}

	.title_txt {
		width: 96rpx;
		height: 48rpx;
		font-weight: 500;
		font-size: 32rpx;
		color: #067CFF;
		text-align: center;
		margin: 110rpx auto 0px;
		z-index: 2;
	}

	.gridbox {
		width: 100%;
		height: 480rpx;
		display: flex;
		padding: 48rpx 60rpx;
		box-sizing: border-box;
		flex-wrap: wrap;

		.itembox {
			width: 104rpx;
			height: 156rpx;
			margin-right: 70rpx;

			&:nth-child(4) {
				margin-right: 0; // 第四个元素移除右边距
			}

			.txt {
				width: 112rpx;
				height: 40rpx;
				font-weight: 400;
				font-size: 28rpx;
				color: #000000;
				text-align: center;
				margin-top: 12rpx;
			}
		}

	}

	.wnbox {
		width: 100%;
		height: 160rpx;
		padding: 0 30rpx;
		box-sizing: border-box;
		display: flex;
		justify-content: space-between;

		.shiwbox {
			width: 332rpx;
			height: 160rpx;
			background: #FFEBEB;
			border-radius: 32rpx 32rpx 32rpx 32rpx;
			position: relative;

			.kdtxt {
				width: 176rpx;
				height: 82rpx;
				position: absolute;
				top: 16rpx;
				left: 20rpx;

				.siwu {
					width: 158rpx;
					height: 48rpx;
					font-weight: bold;
					font-size: 32rpx;
					color: #000000;
					text-align: left;
				}

				.xiaotxt {
					width: 176rpx;
					height: 34rpx;
					font-weight: 400;
					font-size: 22rpx;
					color: #000000;
					text-align: left;
				}
			}
		}

		.wanneng {
			width: 332rpx;
			height: 160rpx;
			background: #FFF5EB;
			border-radius: 32rpx 32rpx 32rpx 32rpx;
			position: relative;

			.kdtxt {
				width: 176rpx;
				height: 82rpx;
				position: absolute;
				top: 16rpx;
				left: 20rpx;

				.siwu {
					width: 158rpx;
					height: 48rpx;
					font-weight: bold;
					font-size: 32rpx;
					color: #000000;
					text-align: left;
				}

				.xiaotxt {
					width: 176rpx;
					height: 34rpx;
					font-weight: 400;
					font-size: 22rpx;
					color: #000000;
					text-align: left;
				}
			}
		}
	}

	.ikz-banner-box {
		position: relative;
		width: 95%;
		margin: 20rpx auto 0px;

	}

	.ikz-location {
		box-sizing: border-box;
		position: absolute;
		top: 30rpx;
		left: 50rpx;
		display: flex;
		align-items: center;
		padding: 10rpx 40rpx 10rpx 30rpx;
		background: rgba(000, 000, 000, 0.3);
		color: #fff;
		border-radius: 70rpx;
		font-size: 25rpx;


	}

	.ikz-location-img {
		width: 40rpx;
		height: 40rpx;
		margin-right: 10rpx;
	}

	/* ad */
	.ikz-ad {
		width: 95%;
		margin: 16rpx auto;
	}

	.ikz-ad-img {
		width: 100%;
		height: 150rpx;
	}

	.changeMode {
		position: fixed;
		right: 2.5%;
		bottom: 500rpx;
		padding-bottom: constant(safe-area-inset-bottom);
		/* 兼容 iOS < 11.2 */
		padding-bottom: env(safe-area-inset-bottom);
		/* 兼容 iOS >= 11.2 */
		z-index: 9999;
	}

	.changeMode image {
		width: 120rpx;
		height: 120rpx;
	}

	/* ad */
</style>